package com.yang.reflectionstudy;

import com.yang.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class demo02 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> aClass = Class.forName("com.yang.Student");
//        Field[] fields = aClass.getFields();
//        for (Field field : fields) {
//            System.out.println(field);
//        }
        Field[] declaredField = aClass.getDeclaredFields();
        for (Field field : declaredField) {
            System.out.println(field);
        }

        Field addresses = aClass.getField("address");
        Constructor<?> constructor = aClass.getConstructor();
        Object o = constructor.newInstance();
        addresses.set(o, "西安");
        System.out.println(o);
//        Student student = new Student();
//        student.address="西安";
//        System.out.println(student);
    }
}
